package com.syni.mdd.yhd.common.all.dao.jpa;

import com.syni.mdd.yhd.common.all.dao.BaseJPADao;
import com.syni.mdd.yhd.common.all.entity.BmsBusiness;
import com.syni.mdd.yhd.common.all.entity.BmsUserBusiness;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;
import java.util.Set;

public interface BmsUserBusinessDao extends BaseJPADao<BmsUserBusiness,Integer> {
    List<BmsUserBusiness> findByBmsUserId(Integer userId);

    List<BmsUserBusiness> findByBmsUserIdAndBmsBusinessId(Integer userId,Integer businessId);

    @Query(value = "select bub.id,bub.bms_user_id,bub.name_in_store,bub.remark,bub.new_time from bms_user_business bub " +
            "left join bms_dx_client_role bdcr on bub.bms_user_id = bdcr.bms_user_id " +
            "where bub.bms_business_id =?1 and bdcr.role_id = ?2",nativeQuery = true)
    List<Map<String,Object>> selfFindBusinessIdAndRoleId(Integer businessId, Integer roleId, Pageable pageable);

    @Query(value = "select bub.id,bub.bms_user_id,bub.name_in_store,bub.remark,bub.new_time from bms_user_business bub " +
            "left join bms_dx_client_role bdcr on bub.bms_user_id = bdcr.bms_user_id " +
            "where bub.bms_business_id =?1 and bdcr.role_id = ?2",nativeQuery = true)
    List<Map<String,Object>> selfFindBusinessIdAndRoleId(Integer businessId, Integer roleId);


    @Query(value = "select count(bub.id) num from bms_user_business bub left join " +
            "bms_dx_client_role bdcr on bub.bms_user_id = bdcr.bms_user_id " +
            "where bub.bms_business_id =?1 and  bdcr.role_id = ?2",nativeQuery = true)
    Integer selfCountBusinessAssistantNum(Integer businessId,Integer roleId);

}
